<!doctype html>
<html xmlns:th="http://www.thymeleaf.org" xmlns="http://www.w3.org/1999/html">

	<head>
		<meta charset="utf-8">
		<title>我的群组-我加入的群</title>
		<link href="../c/base.css" rel="stylesheet" type="text/css">
		<link href="../c/toefl.css" rel="stylesheet" type="text/css">
		<link href="../alert/Fytx_Tips.css" rel="stylesheet" type="text/css" />
		<link href="../c/bootstrap.min.css" rel="stylesheet" type="text/css">
		<script src="../j/jquery-2.1.0.js" type="text/javascript" charset="utf-8"></script>
		<script src="../j/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../user/js/group.js" type="text/javascript" charset="utf-8"></script>
		<!--配置样式（也可以默认使用）-->
		<script type="text/javascript" src="../alert/Fytx_Tips_Config.js"></script>
		<!--美化脚本程序-->
		<script type="text/javascript" src="../alert/Fytx_Tips.js"></script>
	</head>
	<style>
		.nowPage {
			color: red;
		}
	</style>
	<body>

		<div class="doc910 ">
			<div class="flcb_cardMenu">
				<ul>

					<li class="on" th:unless="${session.loginMessage eq 'teacher'}">
						<a href="###" id="myJoin">我加入的群</a>
					</li>
					<li  class="on" th:if="${session.loginMessage eq 'teacher'}">
						<a href="###" id="myCreate">我建立的群</a>
					</li>
					<li th:if="${session.loginMessage eq 'teacher'}">
						<a href="###" id="create">我要建群</a>
					</li>
				</ul>
			</div>

			<div id="myJoinContent"  th:unless="${session.loginMessage eq 'teacher'}"  >

				<div class="flcb_myGroup"th:each="g:${session.my_group.list}" >
					<form action="/toMyGroup" method="post" id="groupform">
						<input type="hidden" name="pageNum" id="pageNum" th:value="${session.my_group.pageNum}">
					<dl th:each="u:${g.groupuser}" th:if="${u.admin_id eq session.sess_user.user_id}">
						<dt><a href="#"><img th:src="${g.img_url}"></a></dt>
						<dd>
							<div class="flcb_myGroupClass">
								<h3>[[${g.group_name}]]</h3>
							</div>
							<div class="flcb_myGroupTime"><span>群主：[[${g.teacher.login_name}]]</span></div>
							<div class="flcb_myGroupText">[[${g.group_desc}]]</div>
							<div class="flcb_cardButton">
								<a th:href="@{/tochat(id=${g.group_id})}" target="_parent">进群聊天</a>
								<a th:href="@{/toGroupDetails(id=${g.group_id})}" target="_parent">群信息</a>
								<a href="###" th:if="${u.type=='0'}" data-toggle="modal" data-target=".modal"  th:onclick="getValue([[${g.group_type}]],[[${g.group_id}]]);">申请做群管理员</a>
								<a  th:href="@{/eixtGroup1(gid=${g.group_id},uid=${session.sess_user.user_id})}">退出该群</a>
							</div>
						</dd>
					</dl>
					</form>
				</div>

				<div class="pageList">
					<ul>
						<li th:if="${session.my_group.pageNum != 1}"><a href="###"
																		  onclick="searchGroup(1)">首页</a></li>
						<li th:each="pages:${session.my_group.navigatepageNums}"><a href="###"
																					  th:class="${pages == session.my_group.pageNum} ? nowPage : ''"
																					  th:onclick="searchGroup([[${pages}]])">【[[${pages}]]】</a></li>
						<li th:if="${session.my_group.pageNum != session.my_group.pages}"><a
								href="###"
								th:onclick="searchGroup([[${session.my_group.pages}]])">最后一页</a></li>
						<li th:if="${session.my_group.pageNum != 1}"><a href="###"
																		  class="pret"
																		  th:onclick="searchGroup([[${session.my_group.prePage}]])">上一页</a></li>
						<li th:if="${session.my_group.pageNum != session.my_group.pages}"><a
								href="###" class="next"
								th:onclick="searchGroup([[${session.my_group.nextPage}]])">下一页</a></li>
					</ul>
				</div>

			</div>

			<div id="myCreateContent"  style="display:block;" th:if="${session.loginMessage eq 'teacher'}">
				<div class="flcb_myGroup" th:each="t:${session.teacher_group.list}">
					<form action="/toMyGroup" method="post" id="group1form">
						<input type="hidden" name="pageNum" id="pageNum1" th:value="${session.teacher_group.pageNum}">
					<dl>
						<dt><a href="#"><img th:src="${t.img_url}"></a></dt>
						<dd>
							<div class="flcb_myGroupClass">
								<h3>[[${t.group_name}]]</h3>
							</div>
							<div class="flcb_myGroupTime"><span>群主：[[${session.sess_user.login_name}]]</span></div>
							<div class="flcb_myGroupText">[[${t.group_desc}]]</div>
							<div class="flcb_cardButton">
								<a th:href="@{/tochat(id=${t.group_id})}">进群聊天</a>
								<a th:href="@{/toGroupDetails(id=${t.group_id})}"  target="_parent">群信息</a>
								<a th:href="@{/toeditGroup(gid=${t.group_id})}" target="_parent">编辑资料</a>
								<a  th:href="@{/destoryGroup1(gid=${t.group_id})}">解散群</a>
							</div>
						</dd>
					</dl>
				</form>
				</div>
				<div class="pageList">
					<ul>
						<li th:if="${session.teacher_group.pageNum != 1}"><a href="###"
																		onclick="searchGroup1(1)">首页</a></li>
						<li th:each="pages:${session.teacher_group.navigatepageNums}"><a href="###"
																					th:class="${pages == session.teacher_group.pageNum} ? nowPage : ''"
																					th:onclick="searchGroup1([[${pages}]])">【[[${pages}]]】</a></li>
						<li th:if="${session.teacher_group.pageNum != session.teacher_group.pages}"><a
								href="###"
								th:onclick="searchGroup1([[${session.teacher_group.pages}]])">最后一页</a></li>
						<li th:if="${session.teacher_group.pageNum != 1}"><a href="###"
																		class="pret"
																		th:onclick="searchGroup1([[${session.teacher_group.prePage}]])">上一页</a></li>
						<li th:if="${session.teacher_group.pageNum != session.teacher_group.pages}"><a
								href="###" class="next"
								th:onclick="searchGroup1([[${session.teacher_group.nextPage}]])">下一页</a></li>
					</ul>
				</div>

			</div>

			<div id="createContent" style="display: none;" th:if="${session.loginMessage eq 'teacher'}">
				<form class="form-horizontal" action="createGroup" method="post" id="groupForm1">
					<div class="form-group">
						<label for="" class="col-sm-2 control-label">选择群类别</label>
						<div class="col-sm-10">
							<select name="group_type" class="form-control">
								<option value="1">同城考试群</option>
								<option value="2">考试场次群</option>
								<option value="3">名师学堂群</option>
								<option value="4">结伴备考群</option>
							</select>
						</div>
					</div>
					<div class="form-group">
						<label  class="col-sm-2 control-label" >群名称</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="group_name" name="group_name"  placeholder="名称">
						</div>
					</div>
					
					<div class="form-group">
						<label  class="col-sm-2 control-label">上传群头像</label>
						<div class="col-sm-10">
							<div class="flcb_cardBuildZp"><img id="pic" style="cursor: pointer" src="../i/240x240.png" width="240" height="240"></div>
							<input id="upload" name="file" accept="image/*" type="file" style="display: none">
							<input id="img_url" type="hidden" name="img_url" />
						</div>
					</div>
					<div class="form-group">
						<label  class="col-sm-2 control-label">群介绍</label>
						<div class="col-sm-10">
							<textarea class="form-control" name="group_desc" id="group_desc" placeholder="此处是群介绍"></textarea>
						</div>
					</div>
					<div class="form-group">
						<label for="" class="col-sm-2 control-label">群规则</label>
						<div class="col-sm-10">
							<textarea class="form-control" name="group_rule" id="group_rule" placeholder="此处是群规则"></textarea>
						</div>
					</div>
					
					<div class="form-group">
						<div class="col-sm-offset-2 col-sm-10">
							<button  class="btn btn-success" type="button" onclick="checkSub()">确定</button>
							<button type="reset" class="btn btn-warning">重置</button>
						</div>
					</div>
				</form>

				

			</div>
        <form action="/applyAdmin" method="post" id="applyform">
			<div class="modal fade" tabindex="-1" role="dialog">
				<div class="modal-dialog" role="document">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
							<h4 class="modal-title">申请信息</h4>
                            <input type="hidden" class="sss" name="group_id">
                            <div th:if="${session.loginMessage == 'user'}">
                            <input type="hidden"  name="user_id" th:value="${session.sess_user.user_id}">
                            </div>
                            </div>
						<div class="modal-body">
							<div class="layerQzBody">
								<div class="layerQzH3 aaa"> </div>
								<div class="layerQzForm">
									<textarea name="apply_desc" cols="" rows="" class="layerQzInput" placeholder="申请理由"></textarea>
									<a class="layerQzButton" href="###" onclick="applySub()">提交审核</a>
								</div>
							</div>

						</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
							<!--<button type="button" class="btn btn-primary">保存</button>-->
						</div>
					</div>
					<!-- /.modal-content -->
				</div>
				<!-- /.modal-dialog -->
			</div>
        </form>
		</div>
	</body>
<script type="text/javascript">

	function searchGroup(pageNum){
		$("#pageNum").val(pageNum);
		$("#groupform").submit();
	}

	function searchGroup1(pageNum){
		$("#pageNum1").val(pageNum);
		$("#group1form").submit();
	}

   function getValue(s,k){
       var aa="同城考试群";
       switch (s) {
           case 1:aa="同城考试群"; break;
           case 2:aa="考试场次群"; break;
           case 3:aa="名师学堂群"; break;
           case 4:aa="结伴备考群"; break;
       }
       $(".aaa").text('本群是'+' '+aa);
            $(".sss").val(k);
   }
    function applySub(){
       $("#applyform").submit();
    }


	function checkSub() {
		var  group_name =$("#group_name").val();
		var img_url =$("#img_url").val();
		var group_desc =$("#group_desc").val();
		var group_rule =$("#group_rule").val();

		if (group_name ==""){
				$.alert("提示信息","群名称不能为空!");
				return false;
		}else if(img_url==""){
				$.alert("提示信息","群头像不能为空!");
			return false;
		}else if(group_desc ==""){
			$.alert("提示信息","群介绍不能为空!");
			return false;
		}else if(group_rule==""){
			$.alert("提示信息","群规则不能为空!");
			return false;
		}else{
			$("#groupForm1").submit();
			return true;
		}
	}
   $(function() {
	   $("#pic").click(function() {
		   $("#upload").click(); //隐藏了input:file样式后，点击头像就可以本地上传
		   $("#upload").on("change", function() {
			   var objUrl = getObjectURL(this.files[0]); //获取图片的路径，该路径不是图片在本地的路径
			   if (objUrl) {
				   $("#pic").attr("src", objUrl); //将图片路径存入src中，显示出图片
				   upimg();
			   }
		   });
	   });
   });
	//建立可存取file的url
	function getObjectURL(file) {
		var url = null;
		if (window.createObjectURL != undefined) { // basic
			url = window.createObjectURL(file);
		} else if (window.URL != undefined) { // mozilla(firefox)
			url = window.URL.createObjectURL(file);
		} else if (window.webkitURL != undefined) { // webkit or chrome
			url = window.webkitURL.createObjectURL(file);
		}
		return url;
	}
	//上传头像到服务器
	function upimg() {
		var pic = $('#upload')[0].files[0];
		var file = new FormData();
		file.append('image', pic);
		$.ajax({
			url: "/uploadImg",
			type: "post",
			data: file,
			cache: false,
			contentType: false,
			processData: false,
			success: function(data) {
				console.log(data);
				var res = data;
				$("#img_url").val(res);
			}
		});

	}
</script>

</html>